<?php
/**
 * Created by PhpStorm.
 * User: zhaox
 * Date: 2018/1/4
 * Time: 15:41
 */
namespace App\Http\Controllers;

use App\Models\Scene;
use App\Models\SeeSum;
use Illuminate\Http\Request;

class SceneController extends Controller {
    public function index($id){
        $scene = Scene::findOrFail($id);
        $seeSum = SeeSum::where("scene_id",$scene->id)->first();
        if (isset($seeSum)){
            $seeSum->see_sum = $seeSum->see_sum + 1;
        }else{
            $seeSum = new SeeSum();
            $seeSum->see_sum = 1;
            $seeSum->scene_id = $scene->id;
        }
        $seeSum ->save();
        return view('pages.scene',['scene'=>$scene]);
    }

    public function getSideList(Request $request){
        $areaId = $request['areaId'];
        $scenes = Scene::where('area_id',$areaId)->paginate(9);
        $sideScene = [];
        foreach ($scenes as $scene){
            $arr = [];
            $arr['img']  = $scene->cover;
            $arr['name'] = $scene->name;
            $arr['url']  = '/index.php/scene/'.$scene->id;
            array_push($sideScene,$arr);
        }
        return response()->json(['res'=>true,'scenes'=>$sideScene]);
    }
}